// miniprogram/pages/me/feedback/feedback.js
var func = require('../../utils/util.js')
const db = wx.cloud.database()
var global = getApp().globalData;

Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  wechat: function (e) {
    this.data.wecaht = e.detail;
  },

  message: function (e) {
    this.data.message = e.detail;
  },

  onSubmit: function () {
    wx.showLoading({
      title: '提交中',
    })
    var schoolId = this.data.schoolId;
    var name = this.data.name;
    var wechat = this.data.wechat;
    var department = this.data.department;
    var message = this.data.message;
    if (message) {
      db.collection('feedback').add({
        data: {
          schoolId: schoolId,
          name: name,
          wechat: wechat,
          department: department,
          message: message,
          date: func.formatTime()
        }
      }).then(res => {
        func.hideLoading('提交成功')
        this.setData({
          message: '',
        })
      }).catch(res => {
        func.hideLoading('提交失败')
      })
    } else {
      wx.showToast({
        title: '留言内容不能为空',
        icon: "none"
      })
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      name: global.name,
      department: global.department,
      schoolId: global.schoolId,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})